<template>
  <transition name='slide' appear>
  <music-list :title='title' :bg-image='bgImage' :songs='songs'></music-list>
  </transition>
</template>

<script>
  import MusicList from 'components/music-list/music-list'
  import { mapGetters } from 'vuex'
  import {getDetail} from 'api'
  import { createSong } from 'common/js/song'

  export default {
    props: {},
    data() {
      return {
        songs:[]
      }
    },
    created(){
      this._getDetail()
    },
    methods: {
      _getDetail() {
        if (!this.disc.id) {
          this.$router.push('/recommend')
          return
        }
        let params = { id: this.disc.id }
        getDetail(params).then(res => {
          this.songs = this._normalizeSong(res.data.playlist.tracks)
          console.log(this.songs)
        })
      },
      _normalizeSong(list) {
        let ret = []
        list.forEach((item) => {
          if (item.id) {
            let song = createSong(item)
            ret.push(song)
          }
        })
        return ret
      }
    },
    computed: {
      title() {
        return this.disc.name
      },
      bgImage() {
        return this.disc.picUrl
      },
      ...mapGetters([
        'disc'
      ])
    },
    components: {
      MusicList
    }
  }
</script>

<style lang="stylus" scoped>
  .slide-enter-active, .slide-leave-active
    transition: all 0.3s
  .slide-enter, .slide-leave-to
    transform: translate3d(100%, 0, 0)
</style>
